﻿@{
    ViewBag.Title = "轮播图";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model DataAccess.Models.Tags
@section Scripts{
    <link rel="stylesheet" type="text/css" href="http://cdn.bootcss.com/Uniform.js/4.2.0/css/default.css">
<script src="~/Scripts/plugins/layer/layer.min.js"></script>
    <script type="text/javascript">

        function ClickPro() {

            layer.open({
                type: 2,
                title: '商品库',
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['893px', '600px'],
                content: '/Product/ProductList'
            });
        }
       

        function IsURL(str_url) {
            var REG = {
                site_url: /^(http(s)?:\/\/)?([a-zA-Z0-9_\.\-\+])+\.([a-zA-Z]{2,6})(:[0-9]+)?\/?$/i,
                url: /^(http(s)?:\/\/)?([a-zA-Z0-9_\.\-\+])+\.([a-zA-Z]{2,6})(:[0-9]+)?\/[0-9a-zA-Z_!~*\'().;\?:@@&=+$,%#-\/]*$/i
            };
            var res = new RegExp(REG.site_url);
            var res2 = new RegExp(REG.url);
            if (res.test(str_url) || res2.test(str_url)) {
                return (true);
            } else {
                return (false);
            }
        }

        $(function () {
            $("#submit").bind("click", Save);

            $('.addkeyword').click(function () {
                $('#search_keyword').show();
                $('#Url').hide();
                $('.checksrc').prop('checked', false);
                $(".productdiv").hide();
            })
            $('.addyourself').click(function () {
              
                $('#search_keyword').hide();
                $('#Url').hide();
                $('.checksrc').prop('checked', false);

                $(".productdiv").show();

            })
            $('.addsrc').click(function ()
            {
                $('#Url').show();
                $('#search_keyword').hide();
                $("#banner_srcedit").prop('checked', true);
               
                $(".productdiv").hide();
            })
        })

        function Save() {
            if ($("#title").val() == "") {
                alert("标题不能为空");
                return false;
            }
         
            if ($("#imgurl").val() == "") {
                alert("请上传图片地址");
                return false;
            }
            var checkedid = $("input[name='source']:checked").val();
            if (checkedid == "") {
                alert("请选择专题的类型");
                return false;
            }
          switch (checkedid) {
              case 1:
                  if ($("#search_keyword").val() == "") {
                      alert("请填写搜索关键词");
                      return false;
                  }
                  break;
              case 2:
                  if ($("#productid").val() == "") {
                      alert("请选择商品");
                      return false;
                  }
                  break;
              case 3:
                  if (!IsURL($("#Url").val()) || $("#Url").val() == "") {
                      alert("请输入正确的URL地址");
                      return false;
                  }
                  break;
            }
            return true;
        }

        function uploadFile(obj) {
            $(".filename").html($("#MaxImgFile").val());
            var formData = new FormData();
            formData.append("file", $("#MaxImgFile")[0].files[0]);
            $.ajax({
                url: "http://changyan.sohu.com/api/2/comment/attachment",
                type: 'POST',
                data: formData,
                processData: false,
                contentType: false,
                beforeSend: function () {
                    console.log("正在进行，请稍候");
                },
                success: function (responseStr) {
                    var json = eval("(" + responseStr + ")");
                    $("#imgurl").val(json.url);
                    $("#showimg img").attr("src", json.url);
                    $("#showimg").show();
                },
                error: function (responseStr) {
                    alert("错误，请重新上传" + responseStr);
                    console.log("error");
                }
            });
        }
    </script>
}

<div class="row">
    <div class="col-lg-12">
        <div class="row">
            <div class="col-lg-12">
                <div class="main-box">
                    <header class="main-box-header clearfix">
                        <h2>轮播图修改</h2>
                    </header>
                    <div class="main-box-body clearfix">
                        <form class="form" id="form1" method="post" action="/Role/AddTags">
                            @Html.Hidden("id", Model.id)


                            <div class="form-group">
                                <label class="control-label col-lg-2" for="title">标题：</label>
                                <input type="text" class="form-control " value="@Model.Title" id="title" name="title" placeholder="输入标题">
                            </div>



                         
                            <div class="form-group">
                                排序：<input type="text" class="form-control" value="@Model.Sort" onkeyup="this.value=this.value.replace(/\D/g,'')" maxlength="5" size="14" id="Sort" name="Sort" placeholder="输入排序的数值越小越靠前">
                            </div>

                            <div class="form-group">

                                <input type="radio" name="TagType" id="optionsRadios1" value="1" @if (Model.TagType == 1 || Model.TagType == 0) { @Html.Raw("checked=''")  }>轮播图
                                <input type="radio" name="TagType" id="optionsRadios2" value="2" @if (Model.TagType == 2) { @Html.Raw("checked=''")   }> 焦点图
                            </div>
                            <div class="form-group">
                                <div class="input-group">
                                    <div class="uploader" id="uniform-MaxImgFile" style="width:auto">
                                        <input type="file" id="MaxImgFile" onchange="uploadFile(this,1)" name="maximgfile">
                                        @Html.Hidden("imgurl", Model.ImgUrl)
                                        <span class="filename">请选择要上传的文件</span><span class="action">选择文件</span>
                                    </div>
                                    <p style="color: Red"> 宽度: 900px, 高度: 280px<br />文件大小100KB左右</p>
                                </div>
                            </div>
                            <div class="form-group" @if (Model.ImgUrl == null) { <text> style="display:none" </text>  } id="showimg">
                                <img src="@Model.ImgUrl" />
                            </div>

                            <div class="form-group">
                                专题商品源：
                                <div class="checking">
                                    <div class="addkeyword" style="margin-left:1rem;">
                                        <label for="banner_keyword">
                                            <input type="radio" name="source" value="1" @Html.Raw(Model.UrlType == "1" ? ("checked='checked'") : "") id="banner_keyword" style="width:1.2rem;height:1.2rem;">
                                            商品关键词搜索：
                                        </label>
                                        <input type="text" value="@Model.searchkeyword" id="search_keyword" name="searchkeyword" class="search_keyword2 form-group" style="margin-left: 2rem; @if(Model.UrlType!="1"){@Html.Raw("display: none;")}">
                                    </div>
                                    <div style="margin-left:1rem;" class="addyourself">
                                        <label for="banner_yourself"><input type="radio" class="form-group" @Html.Raw(Model.UrlType == "2" ? ("checked='checked'") : "") name="source" value="2" id="banner_yourself" style="width:1.2rem;height:1.2rem;">自定义添加商品</label>
                                        <div style="@if(Model.UrlType!="2") {@Html.Raw("display: none;")}" class="productdiv">
                                            <textarea class="form-group" name="productid" id="productid" >@Model.ProductList</textarea>
                                      
                                            <button type="button" onclick="ClickPro()" class="btn btn-success" id="xzproduct">
                                                选择商品
                                            </button>
                                        </div>
                                        
                                    </div>
                                    <div class="am-radio am-text-left addsrc" style="margin-left:1rem;">
                                        <label for="Url">
                                            <input type="radio" class="form-group" name="source" @Html.Raw(Model.UrlType == "3" ? ("checked='checked'") : "") value="3" id="banner_srcedit" style="width:1.2rem;height:1.2rem;" class="checksrc">
                                            跳转到指定网址
                                        </label>
                                        <input type="text"  class="search_keyword2" value="@Model.Url" id="Url" name="Url" style="argin-left: rem; idth: 00px;@if(Model.UrlType!="3") { @Html.Raw("display: none;")}" placeholder="输入跳转的URL">
                                     
                                    </div>
                                </div>
                            </div>


                        


                            <div class="form-group">
                                <button type="submit" id="submit" class="btn btn-success btn-lg">
                                    &nbsp; &nbsp; 保存&nbsp; &nbsp;
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
